package com.iris.live.services.data.repositories;

import com.iris.live.services.data.models.PushApprovalItemSettingModel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * Created by DF on 9/23/2016
 */
public interface PushApprovalItemSettingRepository extends JpaRepository<PushApprovalItemSettingModel, Integer>,
        JpaSpecificationExecutor<PushApprovalItemSettingModel> {

    @Query("select a from PushApprovalItemSettingModel a where a.permit = ?1 and a.type = ?2 and a.brand = ?3")
    PushApprovalItemSettingModel getModelByPermitAndTypeAndBrand(String permit, Integer type, String brand);

    @Modifying
    @Query("delete from PushApprovalItemSettingModel where permit = ?1 and type = ?2 and brand = ?3")
    void deleteModelByPermitAndTypeAndBrand(String permit, Integer type, String brand);

    @Modifying
    @Query("delete from PushApprovalItemSettingModel where permit = ?1 and type = ?2")
    void deleteModelByPermitAndType(String permit, Integer type);


    @Query("select a from PushApprovalItemSettingModel a where a.permit = ?1 and a.type = ?2")
    PushApprovalItemSettingModel getModelByPermitAndType(String permit, Integer type);
}
